package com.jsh.erp.service.auditSynchronization;

import com.alibaba.fastjson.JSONObject;
import com.jsh.erp.service.ICommonQuery;
import com.jsh.erp.utils.Constants;
import com.jsh.erp.utils.IdUtils;
import com.jsh.erp.utils.QueryUtils;
import com.jsh.erp.utils.StringUtil;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.List;
import java.util.Map;

@Service(value = "auditSynchronization_component")
@AuditSynchronizationResource
public class AuditSynchronizationComponent implements ICommonQuery {

    @Resource
    private AuditSynchronizationService auditSynchronizationService;

    @Override
    public Object selectOne(String id) throws Exception {
        return auditSynchronizationService.getAuditSynchronization(id);
    }

    @Override
    public List<?> select(Map<String, String> map)throws Exception {
        return getAuditSynchronizationList(map);
    }

    private List<?> getAuditSynchronizationList(Map<String, String> map) throws Exception{
        String search = map.get(Constants.SEARCH);
        String name = StringUtil.getInfo(search, "name");
        return auditSynchronizationService.select(name, QueryUtils.offset(map), QueryUtils.rows(map));
    }

    @Override
    public Long counts(Map<String, String> map) throws Exception{
        String search = map.get(Constants.SEARCH);
        String name = StringUtil.getInfo(search, "name");
        String remark = StringUtil.getInfo(search, "remark");
        return auditSynchronizationService.countAuditSynchronization(name, remark);
    }

      @Override
    public int insert(JSONObject obj, HttpServletRequest request) throws Exception{
        obj.put("id", IdUtils.getUUID());

        return auditSynchronizationService.insertAuditSynchronization(obj, request);
    }

    @Override
    public int update(JSONObject obj, HttpServletRequest request)throws Exception {
        return auditSynchronizationService.updateAuditSynchronization(obj, request);
    }

    @Override
    public int delete(String id, HttpServletRequest request)throws Exception {
        return auditSynchronizationService.deleteAuditSynchronization(id, request);
    }

    @Override
    public int deleteBatch(String ids, HttpServletRequest request)throws Exception {
        return auditSynchronizationService.batchDeleteAuditSynchronization(ids, request);
    }

    @Override
     public int checkIsNameExist(String id, String name) throws Exception{
        return auditSynchronizationService.checkIsNameExist(id, name);
    }

}
